package com.eastseeway.radioproject.views;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import com.eastseeway.radioproject.databinding.DialogInputPasswordBinding;

public class DialogInputPassword extends Dialog {


    private final DialogInputPasswordBinding mBinding;
    private OnConfirmClickListener mOnConfirmClickListener;

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        // 设置 Dialog 的位置
        Window window = getWindow();
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.gravity = Gravity.CENTER; //TOP弹框最上方
        //设置Dialog的宽度大小
        window.setAttributes(layoutParams);
    }

    public DialogInputPassword(@NonNull Activity activity) {
        super(activity);

        mBinding = DialogInputPasswordBinding.inflate(LayoutInflater.from(activity));
        setContentView(mBinding.getRoot());

        mBinding.confirmButton.setOnClickListener(v -> {
            String s = mBinding.passwordEt.getText().toString();
            if (mOnConfirmClickListener != null) {
                mOnConfirmClickListener.onConfirmClick(s);
            }
        });
    }

    public interface OnConfirmClickListener {
        void onConfirmClick(String password);
    }

    public void setOnConfirmClickListener(OnConfirmClickListener onConfirmClickListener) {
        mOnConfirmClickListener = onConfirmClickListener;
    }

}
